package com.lhy.controller;

import com.lhy.common.vo.Result;
import com.lhy.pojo.User;
import com.lhy.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;

    //添加用户信息到mongodb
    @PostMapping("add")
    public String addUser(User user){
        userService.addUser(user);
        return "信息添加成功";
    }

   @PostMapping("login")
    public Result login(User user, @RequestParam("captcha") String captcha, HttpServletRequest request){
       return userService.login(user,captcha,request);
    }

    //查询所有
    @GetMapping("list")
    public Map<String,Object> selectUserList(){
        return userService.selectUserList();
    }

    //根据账号删除用户信息
    @PostMapping("delete")
    public String deleteUserById(String userId){
        userService.deleteUserById(userId);
        return "删除成功";
    }

    //根据账号修改用户信息
    @PostMapping("update")
    public String updateUserInfo(User user){
        userService.updateUserInfo(user);
        return "修改成功";
    }

    //通过用户账号id查询
    @GetMapping("{userId}")
    public User selectUserById(@PathVariable String userId){
        return userService.selectUserById(userId);
    }

}
